package com.cl.short_video_java.web.admin.shop;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.dto.OrderStats;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.pojo.VideoShopOrder;
import com.cl.short_video_java.service.VideoShopOrderService;
import com.cl.short_video_java.vo.shop.OrderSearch;
import com.cl.short_video_java.vo.shop.OrderStatsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 付
 * @Date 2024-11-14 11:51
 * @Version 1.0
 * @description
 * @since 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {
	private VideoShopOrderService orderService;

	@Autowired
	public OrderController(VideoShopOrderService orderService) {
		this.orderService = orderService;
	}

	@PostMapping("/list")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 5)
	public Result list(@RequestBody OrderSearch search) {
		Page<VideoShopOrder> page = orderService.page(search);
		return Result.success(page);
	}

	@PostMapping("/del")
	@Log(title = "订单",businessType = BusinessType.DELETE)
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 5)
	public Result del(@RequestBody List<String> ids) {
		orderService.del(ids);
		return Result.success();
	}

	/**
	 * 订单统计
	 *
	 * @param type 类型：month-按月计算、day-按天计算
	 * @return
	 */
	@PostMapping("/stats")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 5)
	public Result stats(@RequestBody OrderStatsVo orderStats) {
		List<OrderStats> list = orderService.stats(orderStats);
		return Result.success(list);
	}

}
